<template>
  <!-- 通联认证签约 -->
  <div class="tl-Qualification-container">
    <div class="login-title">完善信息</div>
    <div class="login-user">
      <div class="login-line">
        <div class="login-name">姓名</div>
        <div class="login-val">
          <input type="text" name="name" placeholder="请输入姓名" v-model="formData.name" />
        </div>
      </div>
      <div class="login-line">
        <div class="login-name">证件类型</div>
        <div class="login-val" @click="typeShow = true">
          <input type="text" name="identity_no" placeholder="请选择证件类型" v-model="cardValue" readonly />
        </div>
      </div>
      <div class="login-line bank_card">
        <div class="login-name">证件号码</div>
        <div class="login-val">
          <input type="text" name="cardNo" placeholder="请输入证件号码" v-model="formData.card_no" />
        </div>
      </div>
      <div class="login-line">
        <div class="login-name">手机号码</div>
        <div class="login-val">
          <input type="number" name="mobile" placeholder="请输入手机号码" v-model="formData.mobile" />
        </div>
      </div>
    </div>
    <div class="application-txt">
      <van-checkbox v-model="formData.is_confirm_agreement" shape="square" checked-color="#FE1B49" icon-size="14px" class="application-checkbox">
        <span>签署即同意<span class="application-name" @click.stop="JumpPurchaseAgreement">{{title}}</span></span>
      </van-checkbox>
    </div>
    <div class="btn-box">
      <div class="submit-btn red-gra-btn" @click="clickSubmit">开始签署</div>
    </div>
    <van-popup v-model="typeShow"
      position="bottom"
      closeable
      :style="{ height: '50%' }">
      <div class="type-list">
        <div class="title">请选择证件类型</div>
        <ul>
          <li :class="formData.type == key ? 'li' : ''"
            v-for="(value, key) in code_list"
            :key="key"
            @click="checkType(key, value)">{{value}}</li>
        </ul>
      </div>
     
    </van-popup>
    <van-dialog
        v-model="isShowPurchaseAgreement"
        :title="title"
        close-on-click-overlay
        @confirm="isShowPurchaseAgreement= false"
        class="common-confirm"
      >
        <div class="purchase_agreement_container">
          <div class="purchase_agreement_box">
            <iframe :src="url" style="width: 100%;height: 120vw"></iframe>
          </div>
        </div>
      </van-dialog>
  </div>

</template>

<script>
import { validLength, validateMobile } from '@/utils/validate'
import { getSignAgreement, useYunSignAgency } from '@/api/dz/dzApi'
import Vue from 'vue'
import { Popup } from 'vant'
Vue.use(Popup)
import Store from '@/utils/store'
export default {
  data() {
    return {
      isShowPurchaseAgreement: false,
      shopping_card_recharge_transfer: 0,
      code_list: [],
      title: '',
      cardValue: '',
      url: '',
      formData: {
        id: '',
        name: '',
        type: '', // 实名认证证件类型：1身份证
        card_no: '', // 实名认证证件号
        mobile: '',
        is_confirm_agreement: 0
      },
      typeShow: false
    }
  },
  created() {
    this.init()
  },
  methods: {
    JumpPurchaseAgreement() {
      Store.saveLocal('webSrc', this.url)
      this.$JumpName(this, 'webView', {title: this.title})
    },
    init() {
      this.$loadingWrap.show()
      getSignAgreement().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          // const resData = res.data
          this.code_list = res.data.code_list || []
          this.title = res.data.title || '《在线合同签署协议》'
          this.url = res.data.url || ''
          const user_info = res.data.user_info
          this.formData = {
            id: user_info.id || '',
            name: user_info.name || '',
            type: user_info.type || '',
            card_no: user_info.card_no || '',
            mobile: user_info.mobile || ''
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    checkType(key, value) {
      this.formData.type = key
      this.cardValue = value
      this.typeShow = false
    },
    // 确定签约
    clickSubmit() {
      if (!validLength(this.formData.name)) {
        this.$Error('请输入的姓名')
        return false
      } else if (!validLength(this.formData.type)) {
        this.$Error('请选择证件类型')
        return false
      } else if (!validLength(this.formData.card_no)) {
        this.$Error('请输入的证件号码')
        return false
      } else if (!validateMobile(this.formData.mobile)) {
        this.$Error('请输入正确的手机号码')
        return false
      } else if (!this.formData.is_confirm_agreement) {
        this.$Error('请先同意在线合同签署协议')
        return false
      }
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      useYunSignAgency(this.formData).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.$Error(res.msg)
          this.$JumpName(this, 'my-commission')
        } else {
          this.$Error(res.msg)
        }
      })
    }
  }
}
</script>

<style lang="scss">
@import "src/styles/mixin";
.tl-Qualification-container {
  padding:0 24px;
  @include placeColor(#999);
  input:disabled {
    background: transparent;
  }
  .login-title{
    padding:30px 4px 20px;
    font-size:26px;
    line-height: 30px;
    color:#666;
  }
  .login-title-center{
    padding:30px 4px 20px;
    font-size:26px;
    line-height: 30px;
    color:red;
  }
  .login-user {
    background: #fff;
    width: 100%;
    overflow: hidden;
    border-radius:20px;
  }
  .login-line {
    display: flex;
    width: 100%;
    font-size: 32px;
    border-bottom: 1px solid #ededed;
    padding: 0 30px;
    box-sizing: border-box;
    &.bank_card {
      position: relative;
      // padding-top: 10px;
      // padding-bottom: 20px;
      .tips {
        position: absolute;
        right: 10px;
        bottom: 6px;
        color: #FE1B49;
        font-size: 24px;
      }
    }

    &:last-child{
      border-bottom:0;
    }
    .login-name {
      width: 30%;
      line-height: 96px;
      font-size: 28px;
      color: #333333;
    }
    .login-val {
      width: 70%;
      position: relative;
      text-align:right;
      input {
        width: 100%;
        display: inline-block;
        font-size: 26px;
        color: #666666;
        border: 0;
        text-align: right;
        padding: 20px 0;
        height: 100px;
        background: transparent;
        &.birthday-input {
          padding-right: 50px;
        }
      }
      .icon_calendar {
        font-size: 36px;
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
      }
    }
    &.login-line-verify {
      .login-val{
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .msg-verify-input {
        width: 50%;
        font-size: 26px;
        color: #999999;
      }
      .msg-verify-btn {
        display: inline-block;
        // width: 150px;
        height: 54px;
        padding:0 20px;
        line-height: 54px;
        border-radius: 54px;
        text-align: center;
        font-size: 24px;
        color: #9A9A9A;
        border:2px solid #9A9A9A;
        &.active{
          color:#F30C23;
          border-color:#F30C23;
        }
      }
    }
  }
  .login-user-style2{
    .login-line{
      .login-name{
        width:24%;
      }
      .login-val{
        width:76%;
        text-align:left;
        input{
          text-align:left;
        }
      }
    }
  }
  .application-txt{
    display: flex;
    justify-content: center;
    margin-top:34px;
    .application-name{
      color:#F11227;
    }
  }
  .btn-box {
    padding: 40px 0;
    font-size: 32px;
    text-align: center;
    .submit-btn {
      margin-bottom: 20px;
      border-radius: 92px;
      line-height: 92px;
      color: #fff;
      box-sizing: border-box;
    }
  }
}
.type-list {
  .title {
    text-align: center;
    font-size: 28px;
    padding: 30px 0 40px 0;
    font-weight: bold;
  }
  ul {
    li {
      text-align: center;
      font-size: 26px;
      padding: 40px 0;
      margin: 0 40px;
      border-bottom: 1px solid #f5f5f5;
      &:last-child {
        border: none
      }
      &.li {
        background: url('https://img.wifenxiao.com/h5-wfx/images/check.png') center right no-repeat;
        background-size: 40px 40px;
      }
    }
  }

}
</style>
